var _MAX_SAVED_ITEMS = 5;
var _RECENT_VIEW_COOKIE = "PRVC";
var _ITEM_SEPERATOR = "_ITEM_SEPERATOR";
var _ATTR_SEPERATOR = "_ATTR_SEPERATOR";


//添加最近浏览对象
function addRecentViewItem(attrArray) {
	var value = attrArray.join(_ATTR_SEPERATOR);
	addProductItemToCookie(attrArray[0],value);
}
//添加value到cookie中
function addProductItemToCookie(itemKey,itemValue){
	var cookieValue = getCookie(_RECENT_VIEW_COOKIE);
	if (!cookieValue || cookieValue == null) {
		cookieValue = itemValue;
	} else {
		var itemArray = cookieValue.split(_ITEM_SEPERATOR);
		var flag = false;
		for(var i=0; i<itemArray.length; i++){
			var attrArray = itemArray[i].split(_ATTR_SEPERATOR);
			if(attrArray[0] == itemKey){
				flag = true;
				itemArray[i] = itemValue;
				cookieValue = itemArray.join(_ITEM_SEPERATOR)
				break;
			}
		}
		if(!flag){
			if(itemArray.length >= _MAX_SAVED_ITEMS){
				itemArray.pop();
			}
			cookieValue = itemValue + _ITEM_SEPERATOR + itemArray.join(_ITEM_SEPERATOR);
		}
	}
	var expire = new Date();
	expire.setTime(expire.getTime()+30*24*3600*1000);
	setCookie(_RECENT_VIEW_COOKIE, cookieValue, expire, __ctxPath, null, null); 
	
}

//获得商品浏览历史数组
function getRecentViewItemArray() {
	if(navigator.cookieEnabled){
		var cookieValue = getCookie(_RECENT_VIEW_COOKIE);
		if (cookieValue != null) {
			var resultArray = new Array();
			var itemArray = cookieValue.split(_ITEM_SEPERATOR);
			for(var i=0; i<itemArray.length; i++){
				var attrArray = itemArray[i].split(_ATTR_SEPERATOR);
				resultArray.push(attrArray);
			}
			return resultArray;
		}
	}
	return null;
}


//清除浏览历史
function clearRecentView(){
	deleteCookie(_RECENT_VIEW_COOKIE,__ctxPath);
	$j('#recentProductDiv').empty();
}